package okl.lab.namesFilter.context
{
	import flash.display.DisplayObjectContainer;
	
	import mx.modules.Module;
	
	import okl.lab.components.FilterAndSortList;
	import okl.lab.components.interfaces.IFilterAndSortList;
	import okl.lab.namesFilter.controller.LoadUsersCommand;
	import okl.lab.namesFilter.controller.events.UsersEvent;
	import okl.lab.namesFilter.model.AppModel;
	import okl.lab.namesFilter.model.vo.User;
	import okl.lab.namesFilter.service.HttpUsersService;
	import okl.lab.namesFilter.service.IUsersService;
	import okl.lab.namesFilter.service.MockUserService;
	import okl.lab.namesFilter.view.FilterAndSortListView;
	import okl.lab.namesFilter.view.FilterAndSortModule;
	import okl.lab.namesFilter.view.LoadNamesView;
	import okl.lab.namesFilter.view.interfaces.ILoadNamesList;
	import okl.lab.namesFilter.view.mediators.FilterAndSortMediator;
	import okl.lab.namesFilter.view.mediators.LoadNamesMediator;
	
	import org.robotlegs.base.ContextEvent;
	import org.robotlegs.mvcs.Context;
	
	/**
	 *	RL main application context. 
	 * 
	 *	@author "oleksandr.kulinchenko@gmail.com"
	 */
	public class MainContext extends Context
	{
		public function MainContext(contextView:DisplayObjectContainer=null, autoStartup:Boolean=true)
		{
			super(contextView, autoStartup);
		}
		
		/**
		 *	Method where RL wire your objects together
		 */
		override public function startup():void{
			super.startup();

			
			//mediators
			mediatorMap.mapView(LoadNamesView, LoadNamesMediator, ILoadNamesList);
			mediatorMap.mapView(FilterAndSortListView, FilterAndSortMediator, IFilterAndSortList);
			
			//copmmands
			commandMap.mapEvent(UsersEvent.LOAD, LoadUsersCommand, UsersEvent);
			
			injector.mapSingleton(okl.lab.namesFilter.model.AppModel);
			
			injector.mapSingletonOf(IUsersService, MockUserService);
			//UNCOMMENT to use xml data
			//injector.mapSingletonOf(IUsersService, HttpUsersService);
			
			dispatchEvent(new ContextEvent(ContextEvent.STARTUP));
		}
	}
}